import logging
from django.utils import simplejson
from google.appengine.ext import webapp
from models import *

class Controller(webapp.RequestHandler):
  
  logging.info("|||||||||| APP CACHE REFRESHED ||||||||||")
  
  def __init__(self):
    pass

  def json(self, data):
    if not type(data) is dict and not type(data) is list:
      return self.show_error("JSON output requires dict, list")
    output = simplejson.dumps(data, indent=4)
    self.response.headers.add_header("Content-Type", "application/json")
    self.response.out.write(output)
    return output
    
  def show_error(self, message):
    logging.error("##### 400: " + str(message))
    return web.BadRequest()